package Library;

import java.util.ArrayList;
import java.util.Scanner;
import java.util.TreeMap;

//register类负责提供账号注册
public class register {
//有三个成员变量，都可以有getset方法
	public static int identify = 0;// 身份，0是用户
	public static boolean isAccountRepeat = false;// 判断账号时候出现重复

	public static int getIdentify() {
		return identify;
	}

	public register(int identify) {
		this.identify = identify;

	}

	public String account;
	public String password;

	public String getAccount() {
		return account;
	}

	public void setAccount(String account) {
		this.account = account;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	Scanner input = new Scanner(System.in);

	public void RegisterAnAccount(ArrayList<register> registerList) {

		System.out.println("=========用户注册========");
		System.out.println("欢迎注册账号");
		// 创建账号

		// 判断是否是第一次创建账号，因为isAccountRepeat一开始就是false的，循环无法进行，只能在加一个变量进入循环
		boolean isfirst = true;
		while (isAccountRepeat || isfirst) {
			isfirst = false;
			// 初始化isAccountRepeat，改掉由上一次循环isAccountRepeat = true改变的值
			isAccountRepeat = false;
			System.out.println("请输入您的账号名字:");
			this.account = input.nextLine();
			// 解决重复账号问题
			for (register r : registerList) {
				if (r.getAccount().equals(account)) {
					System.out.println("账号已存在，请重新输入");
					isAccountRepeat = true;
				}
			}
		}
		System.out.println("请输入您的密码:");
		this.password = input.nextLine();

		System.out.println("请再次输入您的密码:");
		String passwordAgain = input.nextLine();
		int i = 0;
		while (true) {
			if (password.equals(passwordAgain)) {
				System.out.println(account + "注册成功");
				break;
			} else {
				System.out.println("您输入的密码有误，请重新输入");
				passwordAgain = input.nextLine();
			}
		}

		// 将账号存储在从main中调用的treemap_cus中，，，，废除
//		treemap_acc_pass.put(account, password);

		// 测试
//		System.out.println(treemap_acc_pass);

	}

}
